import { http, tryHttpError } from '@/utils'

// 登录
export function Login(params) {
  return tryHttpError(http.post('/gwc/pos/login', params, {
    type: 'login',
  }))
}

// h5登录
export function H5Login(params) {
  return tryHttpError(http.post('/gwc/pos/h5_login', params, {
    type: 'login',
  }))
}
// h5取授权登录的地址
export function H5_cfgs(params) {
  return tryHttpError(http.get('/gwc/pos/app_cfgs', params, {}))
}

// 取jssdk配置的数据
export function wxjs_cfgs(params) {
  return tryHttpError(http.get('/gwc/pos/wxjs_cfgs', params, {}))
}

// 支付宝订单
export function ali_vip_pay(params) {
  return tryHttpError(http.post('/gwc/pos/user/ali_vip_pay', params, {}))
}
// 支付宝支付链接
export function ali_pay_url(params) {
  return tryHttpError(http.get('/gwc/pos/user/zpay_url', params, {}))
}


// 修改密码
export function updatePassword(params) {
  return tryHttpError(http.post('/gwc/pos/up_pwd', params))
}

// 获取个人资料
export function getUserInfo(params = {}) {
  return tryHttpError(http.get('/gwc/pos/user/me', params))
}

// 获取统计
export function getStatsInfo(params = {}) {
  return tryHttpError(http.get('/gwc/pos/stats', params))
}

// 获取交易记录
export function getOrderList(params = {}) {
  return tryHttpError(http.get('/gwc/pos/orders', params))
}

// 提现
export function fetchWithdraw(params = {}) {
  return tryHttpError(http.post('/gwc/pos/withdraw', params))
}

// 领取刷卡笔数费
export function fetchNbMoney(params = {}) {
  return tryHttpError(http.post('/gwc/pos/fetch_nbrmb', params, { loading: true }))
}

// 获取提现记录
export function getWithdrawList(params = {}) {
  return tryHttpError(http.get('/gwc/pos/withdraws', params))
}

// 获取提现配置
export function getWithdrawConfig(params = {}) {
  return tryHttpError(http.get('/gwc/pos/pay_cfgs', params))
}

// 获取提现配置
export function getWexinConfig(params = {}) {
  return http.get('/gwc/pos/gzh_cfg', params).then(res => res?.data)
}

// 获取升级配置
export function getLevelConfig(params = {}) {
  return http.get('/gwc/pos/user/plan', params).then(res => {
    console.log('getLevelConfig', res?.data)
    if (res?.data?.code === 0) {
      return res?.data?.data
    }
    return Promise.reject()
  })
}

// 获取升级配置
export function getPayLevelConfig(params = {}) {
  console.log(params);

  return http.post('/gwc/pos/user/vip_pay', params).then(res => {
    if (res?.data?.code === 0) {
      return res?.data?.data
    }
    return Promise.reject()
  })
}

// 提现
export function fetchWithdrawRmb(params = {}) {
  return tryHttpError(http.post('/gwc/pos/withdraw_rmb', params))
}

// 获取上传key
export function getUpToken(params = {}) {
  return tryHttpError(http.get('/gwc/pos/qn_token', params))
}

// 获取签约信息
export function getVipInfo(params = {}) {
  return tryHttpError(http.get('/gwc/pos/user/vip_info', params))
}

// 获取VIP代理奖励规则
export function getVipRule(params = {}) {
  return tryHttpError(http.get('/gwc/pos/user/vip_rule', params))
}

// 获取设备广告内容
export function getDeviceInfo(params = {}) {
  return tryHttpError(http.get('/gwc/pos/user/vip_rule', params))
}

// 获取任务达标记录
export function getTaskLogs(params = {}) {
  return tryHttpError(http.get('/gwc/pos/task_logs', params))
}

// 获取邀请记录
export function getInviteList(params = {}) {
  return tryHttpError(http.get('/gwc/pos/user/invite_stats', params))
}

// 获取设备申请记录
export function getApplyList(params = {}) {
  return tryHttpError(http.get('/gwc/pos/user/apply_list', params))
}

// 提交设备申请
export function saveApply(params) {
  return tryHttpError(http.post('/gwc/pos/user/save_apply', params))
}


